package com.controller;

import com.bean.Orders;
import com.common.R;
import com.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
@CrossOrigin
@RequestMapping("/OrdersController")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;


    @GetMapping("/createOrders")
    private R createOrders(Orders orders){
        try {
            int i = ordersService.createOrders(orders);
//            return R.ok().data(i);这样写不舒服
//            以下代码适合没有返回值的，例如添加，删除
            if (i>0){
                return R.ok();
            }else {
                return R.error();
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
